using System;
using System.Collections.Generic;
using System.IO;
using System.Text;

using Microsoft.SharePoint.Utilities;
using stsdev;

namespace ThemeSolutionProvider
{
    public class ThemeResourceBuilder
    {
        public static void CreateSPThemesXml(string id, string name, string description, string thumbnail, string preview)
        {
            Dictionary<string, string> map = new Dictionary<string, string>(5);
            map.Add("@THEME_ID", id);
            map.Add("@THEME_NAME", SPEncode.HtmlEncode(name));
            map.Add("@THEME_DESCRIPTION", SPEncode.HtmlEncode(description));
            map.Add("@THEME_THUMBNAIL", thumbnail);
            map.Add("@THEME_PREVIEW", preview);

            const string SPTHEMESXML = "SPTHEMES.XML";
            string thisFeatureFolder = Path.Combine(Globals.FeaturesFolder, SolutionBuilder.SolutionName);
            string thisFeatureSPThemesXml = Path.Combine(thisFeatureFolder, SPTHEMESXML);

            FeatureBuilder.EnsureSolutionFolder();
            FeatureBuilder.AddElementFile(SPTHEMESXML);
            MappedTemplateBuilder.Create(thisFeatureSPThemesXml, Properties.Resources.SPTHEMES, map);
            ProjectFileBuilder.AddSourceFile(thisFeatureSPThemesXml, SourceFileTypeEnum.None);
        }

        public static void CreateFeatureThemesJob(string solutionName)
        {
            Dictionary<string, string> map = new Dictionary<string, string>(1);
            map.Add("@SolutionName", solutionName);

            const string FeatureThemesJobCS = "FeatureThemesJob.cs";
            MappedTemplateBuilder.Create(FeatureThemesJobCS, Properties.Resources.FeatureThemesJob, map);
            ProjectFileBuilder.AddSourceFile(FeatureThemesJobCS, SourceFileTypeEnum.Compile);
        }

        public static void CreateImportThemeCss(string themePath, string importPath)
        {
            Dictionary<string, string> map = new Dictionary<string, string>(5);
            map.Add("@IMPORT_PATH", importPath);

            MappedTemplateBuilder.Create(Path.Combine(themePath, "theme.css"), Properties.Resources.ImportTheme, map);
        }
    }
}
